package yifeng.filestatistics.counter;

import java.io.File;

/**
 * 普通统计,单线程
 * @author pengyifeng
 *
 */
public class OrdinaryCounter implements Counter{
	@Override
	public int countFiles(File file) {
		if(file.isFile())
			return 1;
		
		File[] subFiles = file.listFiles();
		if(subFiles == null) 
			return 0;
		
		return countSubFiles(subFiles);	
		
	}

	private int countSubFiles(File[] subFiles) {
		int fileCount = 0;
		for(File aFile : subFiles){
			if(aFile.isDirectory())
				fileCount += countFiles(aFile);
			else
				fileCount++;
		}
		return fileCount;
	}
}
